﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using com.tiyma.components;
using com.tiyma.common;


namespace com.tiyma.web
{
    public partial class _Default : BasePage
    {

        const string m_hot_key_template = "<LI><A title=\"{0}\" href=\"/book/S.aspx?k={1}&t={2}\">{0}</A></LI>";

        public string m_book_key_list = string.Empty;
        public string m_author_key_list = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            BindHotKey();
        }

        private void BindHotKey()
        {
            try
            {
                BookManager t_book_mgr = new BookManager();

                List<string> t_author_list=null;
                List<string> t_book_list = t_book_mgr.GetTopSearch(out t_author_list);

                if (t_book_list == null || t_book_list.Count <= 0)
                    t_book_list = GetBookKey();

                if (t_author_list == null || t_author_list.Count <= 0)
                    t_author_list = GetAuthorKey();

                StringBuilder t_sb = new StringBuilder();

                foreach (string t_key in t_book_list)
                {
                    t_sb.AppendFormat(m_hot_key_template, t_key, HttpUtility.UrlEncode(t_key),(int)Consts.SearchType.BookName);
                }

                m_book_key_list = string.Format("<UL>{0}</UL>", t_sb.ToString());

                t_sb = new StringBuilder();

                foreach (string t_key in t_author_list)
                {
                    t_sb.AppendFormat(m_hot_key_template, t_key, HttpUtility.UrlEncode(t_key),(int)Consts.SearchType.AuthorName);
                }

                m_author_key_list = string.Format("<UL>{0}</UL>", t_sb.ToString());
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取小说热门关键字失败" + ex.ToString());
            }
        }

        private List<string> GetBookKey()
        {
            List<string> t_list = new List<string>();

            t_list.Add("斗破苍穹");
            t_list.Add("盘龙");
            t_list.Add("锦衣夜行");
            t_list.Add("只手遮天");
            t_list.Add("异世邪君");
            t_list.Add("弑天");
            t_list.Add("重生之极品恶魔");
            t_list.Add("随身领取升级礼包");

            return t_list;
        }

        private List<string> GetAuthorKey()
        {
            List<string> t_list = new List<string>();

            t_list.Add("我吃西红柿");
            t_list.Add("无相天劫");
            t_list.Add("西贝猫");
            t_list.Add("天朝书生");
            t_list.Add("唐家三少");
            t_list.Add("石三");
            t_list.Add("十年残梦");
            t_list.Add("蛇吞鲸");

            return t_list;
        }
    }
}
